package io.adrainty.bolee.insurance.service.impl;

import cn.hutool.core.collection.CollUtil;
import io.adrainty.bolee.insurance.models.entity.InsuranceConditionEntity;
import io.adrainty.bolee.insurance.repository.IInsuranceRepository;
import io.adrainty.bolee.insurance.service.IInsuranceConditionService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>InsuranceConditionServiceImpl</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description IInsuranceConditionService
 * @since 2025/8/15 16:21:03
 */

@Service
public class InsuranceConditionServiceImpl implements IInsuranceConditionService {

    @Resource
    private IInsuranceRepository insuranceRepository;

    @Override
    public Boolean createInsuranceCondition(List<InsuranceConditionEntity> conditionEntities) {
        insuranceRepository.createInsuranceConditions(conditionEntities);
        return Boolean.TRUE;
    }

    @Override
    public Boolean updateInsuranceCondition(List<InsuranceConditionEntity> conditionEntities) {
        if (CollUtil.isEmpty(conditionEntities)) return Boolean.TRUE;
        Long insuranceId = conditionEntities.get(0).getInsuranceId();
        insuranceRepository.deleteInsuranceConditionByInsuranceId(insuranceId);
        insuranceRepository.createInsuranceConditions(conditionEntities);
        return Boolean.TRUE;
    }
}
